//
//  XSRefreshControl.swift
//  WeiDo
//
//  Created by XISHAN on 16/3/9.
//  Copyright © 2016年 XISHAN. All rights reserved.
//

import UIKit

private let XSRefreshControlH:CGFloat = 44

enum XSRefreshControlState:Int {
    
    case Normal = 0, Pulling, Refreshing
}

class XSRefreshControl: UIControl {
    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        self.backgroundColor = UIColor.whiteColor()
        self.frame.size = CGSize(width: SCREENW, height: XSRefreshControlH)
        self.frame.origin.y = -XSRefreshControlH
        
        
        addSubview(indicatorView)
        addSubview(arrowImage)
        addSubview(informationLabel)
        
        arrowImage.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(self).offset(-30)
        }
        
        indicatorView.snp_makeConstraints { (make) -> Void in
            make.center.equalTo(arrowImage)
        }
        
        informationLabel.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(arrowImage.snp_trailing)
            make.centerY.equalTo(arrowImage)
        }
        
    }

    
    //懒加载转动控件
    private lazy var indicatorView:UIActivityIndicatorView = {
        
        let indicatorView = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.White)
        return indicatorView
        
    }()
    
    //懒加载箭头图片
    private lazy var arrowImage:UIImageView = UIImageView(image: UIImage(named: "tableview_pull_refresh"))
    
    //懒加载文字Label
    private lazy var informationLabel:UILabel = {
        
        let label = UILabel(textColor: UIColor.blackColor(), fontSize: 12)
        
        label.text = "下拉获取最新数据"
        return label
    }()
}
